<?php
	require_once (dirname(__FILE__)."/../config/Config.inc");
	
	$parm = requestArrayParm($_REQUEST);
	
	$sqlTools = new _SqlTool();
	
	$loginadmin = getLoginAdminInfo();
	
	if(empty($loginadmin) && $parm['m'] != 'login')
	{
		$res['sign'] = '-2';
		echoJSON($res);
		exit;
	}
	
	$res['sign'] = '0';
	
	if($parm['m'] == 'tzStatus')
	{
		if(!adminpermission('Z','100000'))
		{
			$res['sign'] = '-2';
			echoJSON($res);
			exit;
		}
		
		if(!empty($parm['id']))
		{
			unset($wheres,$data);
			$wheres['id'] = $parm['id'];
			$info = $sqlTools->getInfo('touzi', $wheres);
			
			if($info)
			{
				unset($where,$data);
				$where['id'] = $parm['id'];
				$data['status'] = $parm['status'];
				$upres = $sqlTools->setInfo('touzi', $where, $data);
				if($upres)
				{
					saveOpLogInfo('touzi',$info['id'],'更新投资攻略-状态('.$parm['str'].')');
					
					$res['sign'] = '1';
					$res['msg'] = '操作成功';
				}
				else
				{
					$res['sign'] = '0';
					$res['msg'] = '操作失败';
				}
			}
			else
			{
				$res['sign'] = '0';
				$res['msg'] = '数据错误';
			}
		}
		else
		{
			$res['sign'] = '0';
			$res['msg'] = '数据错误';
		}
		
		echoJSON($res);
	}
	
	if($parm['m'] == 'saveTouzi')
	{
		if(!adminpermission('Z','100000'))
		{
			$res['sign'] = '-2';
			echoJSON($res);
			exit;
		}
		
		
		if(!empty($parm['id']))
		{
			//更新
			unset($where,$data);
			$where['id'] = $parm['id'];
			
			$data['desc'] =	$parm['desc'];
		    $data['title'] = $parm['title'];
		    $data['fengmian'] = $parm['fengmian'];
		    $data['video'] = $parm['video'];
		   	$data['audio'] = $parm['audio'];
		    $data['img'] = $parm['img'];
    		$data['content'] = $parm['content'];
    		
			$upres = $sqlTools->setInfo('touzi', $where,$data);
			
			if($upres)
			{
				saveOpLogInfo('touzi',$parm['id'],'更新投资攻略-信息');
				$res['sign'] = '1';
				$res['msg'] = '更新成功';
			}
			else
			{
				$res['sign'] = '0';
				$res['msg'] = '更新失败';
			}
		}
		else
		{
			//添加
			$data['desc'] =	$parm['desc'];
		    $data['title'] = $parm['title'];
		    $data['fengmian'] = $parm['fengmian'];
		    $data['video'] = $parm['video'];
		   	$data['audio'] = $parm['audio'];
		    $data['img'] = $parm['img'];
    		$data['content'] = $parm['content'];
			$data['addtime'] = time();
			$data['status'] = '1';
			$addres = $sqlTools->addInfo('touzi', $data);
			if($addres)
			{
				saveOpLogInfo('touzi',$addres,'添加投资攻略-信息');
				$res['sign'] = '1';
				$res['msg'] = '添加成功';
			}
			else
			{
				$res['sign'] = '0';
				$res['msg'] = '添加失败';
			}
		}
		
		echoJSON($res);
	}
	
	
	if($parm['m'] == 'zrXX')
	{
		if(!adminpermission('S','130000','130001'))
		{
			$res['sign'] = '-2';
			echoJSON($res);
			exit;
		}
		
		if(!empty($parm['id']))
		{
			unset($where,$data);
			$where['id'] = $parm['id'];
			$info = $sqlTools->getInfo('zhuanrang',$where);
			if($info)
			{
				unset($where,$data);
				$where['id'] = $info['id'];
				$where['status'] = '1';
				$data['status'] = '2';
				$upres = $sqlTools->setInfo('zhuanrang',$where,$data);
				if($upres)
				{
					saveOpLogInfo('zhuanrang',$info['id'],'更新转让状态(下线)');
					
					$res['sign'] = '1';
					$res['msg'] = '操作成功';
				}
				else
				{
					$res['sign'] = '0';
					$res['msg'] = '操作失败';
				}
			}
			else
			{
				$res['sign'] = '0';
				$res['msg'] = '数据错误';
			}
		}
		else
		{
			$res['sign'] = '0';
			$res['msg'] = '数据错误';
		}
		
		echoJSON($res);
	}
	
	if($parm['m'] == 'sendSMS')
	{
		if(!adminpermission('D','140001'))
		{
			$res['sign'] = '-2';
			echoJSON($res);
			exit;
		}
		
		if(empty($parm['phone']))
		{
			$res['sign'] = '0';
			$res['msg'] = '缺少手机号';
			echoJSON($res);
			exit;
		}
		
		if(empty($parm['content']))
		{
			$res['sign'] = '0';
			$res['msg'] = '缺少短信内容';
			echoJSON($res);
			exit;
		}
		
		foreach ($parm['phone'] as $key => $value)
		{
			$url = 'http://push3.realsms.cn:38812/api/v10/send?usr=fumeng&pwd=qwer1234&src=188&dest='.$value.'&msg='.$parm['content'];
			$result = curl_send_post($url);
			
			$json = json_decode($result,true);
			
			unset($data);
			
			$data['phone'] = $value;
			
			$data['content'] = $parm['content'];
			
			$data['msgid'] = $json['msgid'][0];
			
			$data['addtime'] = time();
			
			if($json['code'] == 0)
			{
				$data['status1'] = '1';
			}
			else
			{
				$data['status1'] = '0';
			}
			_SqlTool::addInfo('sms', $data);
		}
		
		$res['sign'] = '1';
		$res['msg'] = '发送完成';
		echoJSON($res);
		exit;
	}
	
	if($parm['m'] == 'daoru')
	{
		if(!adminpermission('Y','100000','100003'))
		{
			exit('无权访问');
		}
		
		require_once(ROOTDIR.'source/function/excelread.php');
		
		$name_tmp = $_FILES['file']['tmp_name'];
		$type = strtolower(substr(strrchr($_FILES['file']['name'], '.'), 1)); //获取文件类型
    		$file_name = time() . rand(10000, 99999) . "." . $type;//图片名称
    		$file_url = IMG_DIR . $file_name;//上传后图片路径+名称
    
		if(!is_uploaded_file($name_tmp))
		{
			$res['sign'] = '0';
			$res['msg'] = '上传出错';
			echoJSON($res);
		}
		
		if(!move_uploaded_file($name_tmp, $file_url))//临时文件转移到目标文件夹
		{
			$res['sign'] = '0';
			$res['msg'] = '上传出错';
			echoJSON($res);
		}
		
		
		$excel = new excelread();
		$objPHPExcel = $excel->read($file_url);
		
		if(!$objPHPExcel)
		{
			$res['sign'] = '0';
			$res['msg'] = '上传出错';
			echoJSON($res);
		}
		
		$sheet = $objPHPExcel->getSheet(0);  
		$highestRow = $sheet->getHighestRow(); // 取得总行数  
		$highestColumn = $sheet->getHighestColumn(); // 取得总列数  
		unset($datalist);
		for($j=2;$j<=$highestRow;$j++)
		{
			unset($tempArray);  
		    for($k='A';$k<=$highestColumn;$k++)
		    {
		    	$temp = $objPHPExcel->getActiveSheet()->getCell("$k$j")->getValue();   
		        if($k=='A' || $k=='B')
		        {
		        	if(!empty($temp))
					{
						$tempArray[] = gmdate("Y-m-d H:i:s", PHPExcel_Shared_Date::ExcelToPHP($temp));   
					}
					else
					{
						$tempArray[] = date("Y-m-d H:i:s");
					}
		     	}
		     	else
		     	{  
		           $tempArray[] = $temp;
		        }  
				
				
			}
			
			$datalist[] = $tempArray;
		}
		
		foreach($datalist as $kk=> $v)
		{
			if(!empty($v[4]))
			{
				unset($query);
				$query['loginname'] = $v[4];
				$info = _SqlTool::getInfo('users', $query);
				if(empty($info))
				{
					unset($data);
					$data['loginname'] = $v[4];
					$data['password'] = md5($data['loginname']);
					$data['regtime'] = $data['addtime'] = strtotime($v[0]);
					$data['name'] = $v[6];
					$alipay['alipayNum'] = $v[10];
					$alipay['alipayName'] = $v[11];
					$data['alipay'] = json_encode($alipay);
					$data['source'] = $v[12];
					$useid = _SqlTool::addInfo('users', $data);
				}
				else
				{
					$useid = $info['id'];
				}
				if(!empty($useid))
				{
					unset($query);
					$query['id'] = $useid;
					$userinfo = _SqlTool::getInfo('users', $query);
				}
				
				
				if(!empty($userinfo) && !empty($v[2]) && !empty($v[3]))
				{
					unset($query);
					$query['pt_name'] = $v[2];
					$pingtai = _SqlTool::getInfo('pingtai', $query);
					if(!empty($pingtai))
					{
						unset($query);
						$query['pt_id'] = $pingtai['id'];
						$query['cp_mc'] = $v[3];
						$chanpin = _SqlTool::getInfo('chanpin', $query);
						if(!empty($chanpin))
						{
							unset($query);
							$query['userid'] = $userinfo['id'];
							$query['cp_id'] = $chanpin['id'];
							$query['tztime'] = strtotime($v[1]);
							$query['money'] = floatval($v[7]);
							$tzinfo = _SqlTool::getInfo('tzinfo', $query);
							if(empty($tzinfo))
							{
								unset($data);
								$data['phone'] = $userinfo['loginname'];
								$data['name'] = $userinfo['name'];
								$data['userid'] = $userinfo['id'];
								
								$data['pt_id'] = $chanpin['pt_id'];
								$data['cp_id'] = $chanpin['id'];
								$data['tztime'] = strtotime($v[1]);
								$data['status'] = '2';
								$data['status2'] = '2';
								
								$data['money'] = floatval($v[7]);
								$data['fanli'] = floatval($v[8]);
								$data['fltime'] = strtotime($v[1]);
								$data['cp_fllx'] = $chanpin['cp_fllx'];
								_SqlTool::addInfo('tzinfo', $data);
							}
						}
						
					}
					
				}

			}
		}

		$res['sign'] = '1';
		$res['msg'] = '导入完成';
		echoJSON($res);
	}
	
	if($parm['m'] == 'resetPwd')
	{
		if(!adminpermission('Y','100000','100005'))
		{
			$res['sign'] = '-2';
			echoJSON($res);
			exit;
		}
		
		//判断手机号是否注册
		if(!empty($parm['userid']))
		{
			unset($query);
			$query['id'] = $parm['userid'];
			
			$info = _SqlTool::getInfo('users', $query);
			if(empty($info))
			{
				$res['sign'] = '0';
				$res['msg'] = '用户信息不存在';
				echoJSON($res);
				exit;
			}
			
			unset($where,$data);
			$where['id'] = $info['id'];
			$data['password'] = md5($info['loginname']);
			$resset = _SqlTool::setInfo('users',$where, $data);
			if($resset)
			{
				$res['sign'] = '1';
				$res['msg'] = '重置成功';
			}
			else
			{
				$res['msg'] = '重置失败';
			}
			
		}
		else
		{
			$res['sign'] = '0';
			$res['msg'] = '用户ID为空';
		}
		
		echoJSON($res);
	}
	
	if($parm['m'] == 'jbBank')
	{
		if(!adminpermission('Y','100000','100006'))
		{
			$res['sign'] = '-2';
			echoJSON($res);
			exit;
		}
		
		//判断手机号是否注册
		if(!empty($parm['userid']))
		{
			unset($query);
			$query['id'] = $parm['userid'];
			
			$info = _SqlTool::getInfo('users', $query);
			if(empty($info))
			{
				$res['sign'] = '0';
				$res['msg'] = '用户信息不存在';
				echoJSON($res);
				exit;
			}
			
			unset($where,$data);
			$where['id'] = $info['id'];
			$data['bank'] = '';
			$resset = _SqlTool::setInfo('users',$where, $data);
			if($resset)
			{
				//发送短信通知
				
				
				$res['sign'] = '1';
				$res['msg'] = '解绑成功';
			}
			else
			{
				$res['msg'] = '解绑失败';
			}
			
		}
		else
		{
			$res['sign'] = '0';
			$res['msg'] = '用户ID为空';
		}
		
		echoJSON($res);
	}
	
	if($parm['m'] == 'jbAliPay')
	{
		if(!adminpermission('Y','100000','100006'))
		{
			$res['sign'] = '-2';
			echoJSON($res);
			exit;
		}
		
		//判断手机号是否注册
		if(!empty($parm['userid']))
		{
			unset($query);
			$query['id'] = $parm['userid'];
			
			$info = _SqlTool::getInfo('users', $query);
			if(empty($info))
			{
				$res['sign'] = '0';
				$res['msg'] = '用户信息不存在';
				echoJSON($res);
				exit;
			}
			
			unset($where,$data);
			$where['id'] = $info['id'];
			$data['alipay'] = '';
			$resset = _SqlTool::setInfo('users',$where, $data);
			if($resset)
			{
				//发送短信通知
				
				
				$res['sign'] = '1';
				$res['msg'] = '解绑成功';
			}
			else
			{
				$res['msg'] = '解绑失败';
			}
			
		}
		else
		{
			$res['sign'] = '0';
			$res['msg'] = '用户ID为空';
		}
		
		echoJSON($res);
	}
	
	
	
	if($parm['m'] == 'addUser')
	{
		if(!adminpermission('Y','100000','100001'))
		{
			$res['sign'] = '-2';
			echoJSON($res);
			exit;
		}
		
		//判断手机号是否注册
		if(!empty($parm['phone']))
		{
			unset($query);
			$query['loginname'] = $parm['phone'];
			
			$info = _SqlTool::getInfo('users', $query);
			if(!empty($info))
			{
				$res['sign'] = '0';
				$res['msg'] = '手机号码已经注册';
				echoJSON($res);
				exit;
			}
			
			unset($data);
			$data['loginname'] = $parm['phone'];
			$data['password'] = md5($parm['phone']);
			$data['regtime'] = time();
			$data['source'] = 'system';
			$data['addtime'] = time();
			$resadd = _SqlTool::addInfo('users', $data);
			if($resadd)
			{
				//发送短信通知
				
				
				$res['sign'] = '1';
				$res['msg'] = '添加成功';
			}
			else
			{
				$res['msg'] = '添加失败';
			}
			
		}
		else
		{
			$res['sign'] = '0';
			$res['msg'] = '手机号码为空';
		}
		
		echoJSON($res);
	}
	
	if($parm['m'] == 'saveYaoqing')
	{
		if(!adminpermission('X','130000','130001'))
		{
			$res['sign'] = '-2';
			echoJSON($res);
			exit;
		}
		
		if(!empty($parm['tz1']) && !empty($parm['jl1']))
		{
			unset($where);
			$where['type'] = '1';
			$info = _SqlTool::getInfo('yqguize', $where);
			if(!empty($info))
			{
				unset($where,$data);
				$where['id'] = $info['id'];
				$data['touzi'] = floatval($parm['tz1']);
				$data['jiangli'] = floatval($parm['jl1']);
				_SqlTool::setInfo('yqguize', $where, $data);
			}
			else
			{
				unset($data);
				$data['type'] = '1';
				$data['style'] = '1';
				$data['touzi'] = floatval($parm['tz1']);
				$data['jiangli'] = floatval($parm['jl1']);
				_SqlTool::addInfo('yqguize', $data);
			}
			
			
		}
		
		if(!empty($parm['tz2']) && !empty($parm['jl2']))
		{
			unset($where);
			$where['type'] = '2';
			$info = _SqlTool::getInfo('yqguize', $where);
			if(!empty($info))
			{
				unset($where,$data);
				$where['id'] = $info['id'];
				$data['touzi'] = floatval($parm['tz2']);
				$data['jiangli'] = floatval($parm['jl2']);
				_SqlTool::setInfo('yqguize', $where, $data);
			}
			else
			{
				unset($data);
				$data['type'] = '2';
				$data['style'] = '1';
				$data['touzi'] = floatval($parm['tz2']);
				$data['jiangli'] = floatval($parm['jl2']);
				_SqlTool::addInfo('yqguize', $data);
			}
			
			
		}
		
		if(!empty($parm['jl3']))
		{
			unset($where);
			$where['type'] = '3';
			$info = _SqlTool::getInfo('yqguize', $where);
			if(!empty($info))
			{
				unset($where,$data);
				$where['id'] = $info['id'];
				$data['jiangli'] = floatval($parm['jl3']);
				_SqlTool::setInfo('yqguize', $where, $data);
			}
			else
			{
				unset($data);
				$data['type'] = '3';
				$data['style'] = '2';
				$data['jiangli'] = floatval($parm['jl3']);
				_SqlTool::addInfo('yqguize', $data);
			}
			
		}
		
		$res['sign'] = '1';
		$res['msg'] = '保存成功';
		echoJSON($res);
		
	}
	
	
	if($parm['m'] == 'saveIndexCP')
	{
		if(!adminpermission('N','120000','120001'))
		{
			$res['sign'] = '-2';
			echoJSON($res);
			exit;
		}
		
		unset($where);
		$where['type'] = 'index';
		
		$tuijian = _SqlTool::getInfo('tuijian', $where);
		
		

		if(!empty($tuijian))
		{
			unset($where,$data);
			$where['id'] = $tuijian['id'];
			$data['content'] = json_encode($parm['items']);
			$resup = _SqlTool::setInfo('tuijian', $where, $data);
			if($resup)
			{
				$res['sign'] = '1';
				$res['msg'] = '保存成功';
			}
			else
			{
				$res['msg'] = '保存失败';
			}
			echoJSON($res);
		}
		else
		{
			unset($data);
			$data['type'] = 'index';
			$data['content'] = json_encode($parm['items']);
			$resadd = _SqlTool::addInfo('tuijian',$data);
			if($resadd)
			{
				$res['sign'] = '1';
				$res['msg'] = '保存成功';
			}
			else
			{
				$res['msg'] = '保存失败';
			}
			echoJSON($res);
		}
	}
	
	if($parm['m'] == 'getCPList')
	{
		unset($wheres, $pages, $sorts,$list);
		if(!empty($parm['ptid']))
		{
			$wheres['pt_id'] = $parm['ptid'];
		}
		$wheres['cp_status'] = '2';
		
		$p = $pages['page'] = getParam('page','request','1');
		
		$pages['rows'] = 10;
		$sorts['addtime'] = 'desc';
		$resData = _SqlTool::getList('chanpin', $wheres, $pages, $sorts);
		
		foreach ($resData['list'] as $key => $v)
		{
			unset($temp);
			unset($info,$query);
			$query['id'] = $v['pt_id'];
			$pingtai = _SqlTool::getInfo('pingtai', $query);
			$temp['id'] = $v['id'];
			$temp['pt_name'] = $pingtai['pt_name'];
			$temp['cp_name'] = $v['cp_mc'];
			
			if($v['cp_tzqxlx'] == 'day')
			{
				$temp['qixian'] = $v['cp_tzqx'].'天';;
			}
			
			
			if($v['cp_tzqxlx'] == 'month')
			{
				$temp['qixian'] = $v['cp_tzqx'].'月';
			}
			
			
			$list[] = $temp;
		}
		
		$ps = $resData['pages'];
		
		if(empty($ps))
		{
			$ps = 1;
		}
		
		$res['sign'] = '1';
		$res['page'] = pageshow_rili($p,$ps);
		$res['list'] = $list;
		
		echoJSON($res);
	}
	
	if($parm['m'] == 'editpwd')
	{
		if(md5($parm['pwdo']) == getLoginAdminInfo('password'))
		{
			unset($wheres,$data);
			$wheres['id'] = getLoginAdminInfo('id');
			$data['password'] = md5($parm['pwdn1']);
			
			if(!empty($wheres['id']))
			{
				$resup = _SqlTool::setInfo('admin', $wheres, $data);
			}
			
			if($resup)
			{
				$res['sign'] = '1';
				$res['msg'] = '修改成功';
				echoJSON($res);
				exit;
			}
			else
			{
				$res['sign'] = '0';
				$res['msg'] = '修改失败';
				echoJSON($res);
				exit;
			}
		}
		else
		{
			$res['sign'] = '0';
			$res['msg'] = '原密码错误';
			echoJSON($res);
			exit;
		}
	}
	
	if($parm['m'] == 'getTZList')
	{
		if(!adminpermission('Y','100000','100001'))
		{
			$res['sign'] = '-2';
			echoJSON($res);
			exit;
		}
		if(empty($parm['userid']))
		{
			$res['sign'] = '0';
			$res['msg'] = '用户ID不存在';
			echoJSON($res);
			exit;
		}
		unset($list,$wheres, $pages, $sorts, $between);
		$wheres['userid'] = $parm['userid'];
		if(!empty($parm['type']))
		{
			$wheres['status'] = $parm['type'];
		}
		$p = $pages['page'] = getParam('page','request','1');
		
		$pages['rows'] = 5;
		$resData = _SqlTool::getList('tzinfo', $wheres, $pages, $sorts, $between);
		
		foreach ($resData['list'] as $key => $v)
		{
			unset($temp);
			unset($info,$query);
			$query['id'] = $v['pt_id'];
			$pingtai = _SqlTool::getInfo('pingtai', $query);
			$temp['pt_name'] = $pingtai['pt_name'];
			unset($info,$query);
			$query['id'] = $v['cp_id'];
			$chanpin = _SqlTool::getInfo('chanpin', $query);
			$temp['cp_name'] = $chanpin['cp_mc'];
			
			if($chanpin['cp_tzqxlx'] == 'day')
			{
				$temp['qixian'] = $chanpin['cp_tzqx'].'天';;
			}
			
			
			if($chanpin['cp_tzqxlx'] == 'month')
			{
				$temp['qixian'] = $chanpin['cp_tzqx'].'月';
			}
			
			
			$temp['tztime'] = time_formart($v['tztime'],'1');
			
			if($v['status'] == '1')
			{
				$temp['status'] = '待确认';	
			}
			
			if($v['status'] == '2')
			{
				$temp['status'] = '已投标';	
			}
			
			if($v['status'] == '3')
			{
				$temp['status'] = '未投标';	
			}
				
			
			
			$list[] = $temp;
		}
		
		$ps = $resData['pages'];
		
		if(empty($ps))
		{
			$ps = 1;
		}
		
		$res['sign'] = '1';
		$res['page'] = pageshow_rili($p,$ps);
		$res['list'] = $list;
		
		echoJSON($res);
	}
	
	if($parm['m'] == 'getJYList')
	{
		if(!adminpermission('Y','100000','100001'))
		{
			$res['sign'] = '-2';
			echoJSON($res);
			exit;
		}
		
		if(empty($parm['userid']))
		{
			$res['sign'] = '0';
			$res['msg'] = '用户ID不存在';
			echoJSON($res);
			exit;
		}
		unset($wheres, $pages, $sorts,$list);
	
		$wheres['userid'] = $parm['userid'];
		
		if($parm['type'] == '1')
		{
			//返利
			$wheres['money'] = array('>',0);
		}
		else if($parm['type'] == '2')
		{
			//提现
			$wheres['money'] = array('<',0);
		}
		
		$wheres['addtime'] =  array('<=',time());
		
		$p = $pages['page'] = getParam('page','request','1');
		
		$pages['rows'] = 5;
		
		$sorts['id'] = 'desc';
		
		$resData = _SqlTool::getList('jyinfo', $wheres, $pages, $sorts);
		
		foreach ($resData['list'] as $key => $val)
		{
			unset($temp);
			$temp['title'] = $val['title'];
			if($val['money']>=0)
			{
				$temp['type'] = '1';
				$temp['money'] = '+'.$val['money'];
			}
			else
			{
				$temp['type'] = '2';
				$temp['money'] = $val['money'];
			}
			
			$temp['time'] = date('Y-m-d H:i:s',$val['addtime']);
			
			unset($wheres,$between);
		
			$wheres['userid'] = $val['userid'];
			
			$wheres['id'] =  array('<=',$val['id']);
			
			$wheres['addtime'] =  array('<=',time());
			
			$temp['yue'] = _SqlTool::getSum('jyinfo', $wheres, $between, 'money');
			
			$list[] = $temp;
		}
		
		$ps = $resData['pages'];
		
		if(empty($ps))
		{
			$ps = 1;
		}
		
		$res['sign'] = '1';
		$res['page'] = pageshow_rili($p,$ps);
		$res['list'] = $list;
		
		echoJSON($res);
	}
	
	if($parm['m'] == 'FLSH')
	{
		if(!adminpermission('S','110000','110001'))
		{
			$res['sign'] = '-2';
			echoJSON($res);
			exit;
		}
		
		unset($query);
		$query['id'] = $parm['id'];
		$info = _SqlTool::getInfo('tzinfo', $query);
		if(empty($info))
		{
			$res['sign'] = '0';
			$res['msg'] = '投资信息不存在';
			echoJSON($res);
			exit;
		}

		unset($query);
		$query['id'] = $info['cp_id'];
		$chanpin = _SqlTool::getInfo('chanpin', $query);
		if(empty($chanpin))
		{
			$res['sign'] = '0';
			$res['msg'] = '产品信息不存在';
			echoJSON($res);
			exit;
		}
		
		//更新
		unset($where,$touzi,$fanli);
		$where['id'] = $info['id'];
		$where['status'] = '2';
		$where['status2'] = '1';
		$touzi['status2'] = '2';
		
		$fanli['userid'] = $info['userid'];
		$fanli['money'] = round(floatval($info['fanli']),2);
		unset($query);
		$query['id'] = $info['pt_id'];
		$pingtai = _SqlTool::getInfo('pingtai', $query);
		$fanli['title'] = $pingtai['pt_name'].'返利';
		$fanli['addtime'] = $info['fltime'];
		
		unset($query);
		$query['id'] = $info['userid'];
		$users = _SqlTool::getInfo('users', $query);
		if(!empty($users['source']))
		{
			unset($query);
			$query['id'] = $users['source'];
			$pusers = _SqlTool::getInfo('users', $query);
		}
		$upres = _SqlTool::autoFanli($where, $touzi, $fanli,$pusers,$info);
		
		if($upres)
		{
			$phone = $info['phone'];
			$content = '尊敬的比赚用户您好，您已成功投资'.$pingtai['pt_name'].'平台产品，返利金额将于下一个工作日到达您的比赚个人账户，届时请登录比赚官网https://www.bigzhuan.com进行查看，感谢您的支持，祝投资愉快！';
			$url = 'http://push3.realsms.cn:38812/api/v10/send?usr=fumeng&pwd=qwer1234&src=188&dest='.$phone.'&msg='.$content;
			curl_send_post($url);
					
			saveOpLogInfo('tzinfo',$info['id'],'审核返利信息(已确认)');
			$res['sign'] = '1';
			$res['msg'] = '审核成功';
		}
		else
		{
			$res['sign'] = '0';
			$res['msg'] = '审核失败';
		}
		
		echoJSON($res);

	}
	
	if($parm['m'] == 'txSH')
	{
		if(!adminpermission('S','120000','120001'))
		{
			$res['sign'] = '-2';
			echoJSON($res);
			exit;
		}
		
		unset($query);
		$query['id'] = $parm['id'];
		$info = _SqlTool::getInfo('txinfo', $query);
		if(empty($info))
		{
			$res['sign'] = '0';
			$res['msg'] = '提现信息不存在';
			echoJSON($res);
			exit;
		}
		
		//更新
		unset($where,$tixian);
		$where['id'] = $info['id'];
		$where['status'] = '1';
		$tixian['status'] = '2';
		$tixian['optime'] = time();
		$upres = _SqlTool::setInfo('txinfo', $where, $tixian);
		
		if($upres)
		{
			$phone = $info['phone'];
			$content = '尊敬的比赚用户您好，您提现额为'.$info['money'].'元的订单已受理，请及时关注到款状态，比赚登录官网https://www.bigzhuan.com，感谢您的支持，祝投资愉快！';
			$url = 'http://push3.realsms.cn:38812/api/v10/send?usr=fumeng&pwd=qwer1234&src=188&dest='.$phone.'&msg='.$content;
			curl_send_post($url);
			
			saveOpLogInfo('tzinfo',$info['id'],'审核提现信息(已确认)');
			$res['sign'] = '1';
			$res['msg'] = '审核成功';
		}
		else
		{
			$res['sign'] = '0';
			$res['msg'] = '审核失败';
		}
		
		echoJSON($res);

	}
	
	if($parm['m'] == 'tzSH')
	{
		if(!adminpermission('S','100000','100001'))
		{
			$res['sign'] = '-2';
			echoJSON($res);
			exit;
		}
		
		unset($query);
		$query['id'] = $parm['id'];
		$info = _SqlTool::getInfo('tzinfo', $query);
		if(empty($info))
		{
			$res['sign'] = '0';
			$res['msg'] = '投资信息不存在';
			echoJSON($res);
			exit;
		}
		
		unset($query);
		$query['id'] = $info['cp_id'];
		$chanpin = _SqlTool::getInfo('chanpin', $query);
		if(empty($chanpin))
		{
			$res['sign'] = '0';
			$res['msg'] = '产品信息不存在';
			echoJSON($res);
			exit;
		}
		
		if($parm['je'] < 0)
		{
			$res['sign'] = '0';
			$res['msg'] = '数据异常';
			echoJSON($res);
			exit;
		}
		
		if($parm['lx'] < 0)
		{
			$res['sign'] = '0';
			$res['msg'] = '数据异常';
			echoJSON($res);
			exit;
		}
		
		if($parm['fl'] < 0)
		{
			$res['sign'] = '0';
			$res['msg'] = '数据异常';
			echoJSON($res);
			exit;
		}
		
		if($parm['tb'] == '2')
		{
			//更新
			unset($where,$data);
			$where['id'] = $info['id'];
			$where['status'] = '1';
			$where['status2'] = '1';
			$data['money'] = round(floatval($parm['je']),2);
			$data['lixi'] = round(floatval($parm['lx']),2);
			$data['fanli'] = round(floatval($parm['fl']),2);
			$data['fltime'] = strtotime($parm['sj']);
			$data['addtime'] = time();
			if($info['cp_fllx'] == '1')
			{
				$data['status'] = '2';
				$data['status2'] = '2';
				$fanli['userid'] = $info['userid'];  
				$fanli['money'] = floatval($parm['fl']);
				unset($query);
				$query['id'] = $info['pt_id'];
				$pingtai = _SqlTool::getInfo('pingtai', $query);
				$fanli['title'] = $pingtai['pt_name'].'返利';
				
				$fanli['addtime'] = strtotime($parm['sj']);
				
				unset($query);
				$query['id'] = $info['userid'];
				$users = _SqlTool::getInfo('users', $query);
				
				if(!empty($users['source']))
				{
					unset($query);
					$query['id'] = $users['source'];
					$pusers = _SqlTool::getInfo('users', $query);
				}
				
				$info['money'] = floatval($parm['je']);
				$info['fltime'] = strtotime($parm['sj']);
				$upres = _SqlTool::autoFanli($where, $data,$fanli,$pusers,$info);
				
				if($upres)
				{
					$phone = $info['phone'];
					$content = '尊敬的比赚用户您好，您已成功投资'.$pingtai['pt_name'].'平台产品，返利金额将于下一个工作日到达您的比赚个人账户，届时请登录比赚官网https://www.bigzhuan.com进行查看，感谢您的支持，祝投资愉快！';
					$url = 'http://push3.realsms.cn:38812/api/v10/send?usr=fumeng&pwd=qwer1234&src=188&dest='.$phone.'&msg='.$content;
					curl_send_post($url);
				}
				
				
			}
			
			if($info['cp_fllx'] == '2')
			{
				$data['status'] = '2';
				$data['status2'] = '1';
				$upres = _SqlTool::setInfo('tzinfo', $where, $data);
			}
			
			if($upres)
			{
				saveOpLogInfo('tzinfo',$info['id'],'审核投资信息(已投标)');
				$res['sign'] = '1';
				$res['msg'] = '审核成功';
			}
			else
			{
				$res['sign'] = '0';
				$res['msg'] = '审核失败';
			}
			
			echoJSON($res);
		}
		
		if($parm['tb'] == '3')
		{
			//更新
			unset($where,$data);
			$where['id'] = $info['id'];
			$where['status'] = '1';
			$data['status'] = '3';
			$upres = _SqlTool::setInfo('tzinfo', $where, $data);
			if($upres)
			{
				saveOpLogInfo('tzinfo',$info['id'],'审核投资信息(未投标)');
				$res['sign'] = '1';
				$res['msg'] = '审核成功';
			}
			else
			{
				$res['sign'] = '0';
				$res['msg'] = '审核失败';
			}
			
			echoJSON($res);
		}
	}
	
	if($parm['m'] == 'saveSource')
	{
		unset($query);
		$query['name'] = $parm['name'];
		$info = _SqlTool::getInfo('source', $query);
		if(!empty($info))
		{
			$res['sign'] = '0';
			$res['msg'] = '渠道已经存在';
			echoJSON($res);
			exit;
		}
		if(!empty($parm['id']))
		{
			if(!adminpermission('X','120000','120002'))
			{
				$res['sign'] = '-2';
				echoJSON($res);
				exit;
			}
			//更新
			unset($where,$data);
			$where['id'] = $parm['id'];
			$data['name'] = $parm['name'];
			$upres = $sqlTools->setInfo('source',$where,$data);
			if($upres)
			{
				saveOpLogInfo('source',$parm['id'],'更新渠道信息');
				$res['sign'] = '1';
				$res['msg'] = '更新成功';
			}
			else
			{
				$res['sign'] = '0';
				$res['msg'] = '更新失败';
			}
		}
		else
		{
			if(!adminpermission('X','120000','120001'))
			{
				$res['sign'] = '-2';
				echoJSON($res);
				exit;
			}
			//添加
			unset($data);
			$data['name'] = $parm['name'];
			$data['addtime'] = time();
			$data['adduser'] = getLoginAdminInfo('id');
			$addres = $sqlTools->addInfo('source',$data);
			if($addres)
			{
				saveOpLogInfo('source',$addres,'添加渠道信息');
				$res['sign'] = '1';
				$res['msg'] = '添加成功';
			}
			else
			{
				$res['sign'] = '0';
				$res['msg'] = '添加失败';
			}
		}
		
		echoJSON($res);
	}
	
	if($parm['m'] == 'adminReset')
	{
		if(!adminpermission('X','110000','110002'))
		{
			$res['sign'] = '-2';
			echoJSON($res);
			exit;
		}
		
		if(!empty($parm['id']))
		{
			unset($where,$data);
			$where['id'] = $parm['id'];
			$info = $sqlTools->getInfo('admin',$where);
			if($info)
			{
				unset($where,$data);
				$where['id'] = $info['id'];
				$data['password'] = md5('123456');
				$upres = $sqlTools->setInfo('admin',$where,$data);
				if($upres)
				{
					saveOpLogInfo('admin',$info['id'],'重置员工初始密码');
					
					$res['sign'] = '1';
					$res['msg'] = '操作成功';
				}
				else
				{
					$res['sign'] = '0';
					$res['msg'] = '操作失败';
				}
			}
			else
			{
				$res['sign'] = '0';
				$res['msg'] = '数据错误';
			}
		}
		else
		{
			$res['sign'] = '0';
			$res['msg'] = '数据错误';
		}
		
		echoJSON($res);
	}
	
	
	if($parm['m'] == 'adminStatus')
	{
		if($parm['status'] == '3')
		{
			if(!adminpermission('X','110000','110004'))
			{
				$res['sign'] = '-2';
				echoJSON($res);
				exit;
			}
		}
		else
		{
			if(!adminpermission('X','110000','110003'))
			{
				$res['sign'] = '-2';
				echoJSON($res);
				exit;
			}
		}
		
		if(!empty($parm['id']))
		{
			unset($where,$data);
			$where['id'] = $parm['id'];
			$info = $sqlTools->getInfo('admin',$where);
			if($info)
			{
				unset($where,$data);
				$where['id'] = $info['id'];
				$data['status'] = $parm['status'];
				$upres = $sqlTools->setInfo('admin',$where,$data);
				if($upres)
				{
					saveOpLogInfo('admin',$info['id'],'更新人员状态('.$parm['str'].')');
					
					$res['sign'] = '1';
					$res['msg'] = '操作成功';
				}
				else
				{
					$res['sign'] = '0';
					$res['msg'] = '操作失败';
				}
			}
			else
			{
				$res['sign'] = '0';
				$res['msg'] = '数据错误';
			}
		}
		else
		{
			$res['sign'] = '0';
			$res['msg'] = '数据错误';
		}
		
		echoJSON($res);
	}
	
	if($parm['m'] == 'saveAdmin')
	{
		if(!empty($parm['id']))
		{
			if(!adminpermission('X','110000','110002'))
			{
				$res['sign'] = '-2';
				echoJSON($res);
				exit;
			}
			//更新
			unset($where,$data);
			$where['id'] = $parm['id'];
			$data['nickname'] = $parm['nickname'];
			$data['gonghao'] = $parm['gonghao'];
			//$data['loginname'] = $parm['loginname'];
			$data['roleid'] = $parm['role'];
			$data['status'] = $parm['status'];
			$upres = $sqlTools->setInfo('admin',$where,$data);
			if($upres)
			{
				saveOpLogInfo('admin',$parm['id'],'更新人员信息');
				$res['sign'] = '1';
				$res['msg'] = '更新成功';
			}
			else
			{
				$res['sign'] = '0';
				$res['msg'] = '更新失败';
			}
		}
		else
		{
			if(!adminpermission('X','110000','110001'))
			{
				$res['sign'] = '-2';
				echoJSON($res);
				exit;
			}
			
			unset($query);
			$query['loginname'] = $parm['loginname'];
			$info = _SqlTool::getInfo('admin', $query);
			if(!empty($info))
			{
				$res['sign'] = '0';
				$res['msg'] = '登录帐号已存在';
				echoJSON($res);
				exit;
			}
			//添加
			unset($data);
			$data['nickname'] = $parm['nickname'];
			$data['gonghao'] = $parm['gonghao'];
			$data['loginname'] = $parm['loginname'];
			$data['roleid'] = $parm['role'];
			$data['status'] = $parm['status'];
			$data['type'] = 'P';
			$data['password'] = md5('123456');
			$data['addtime'] = time();
			$data['adduser'] = getLoginAdminInfo('id');
			$addres = $sqlTools->addInfo('admin',$data);
			if($addres)
			{
				saveOpLogInfo('admin',$addres,'添加人员信息');
				$res['sign'] = '1';
				$res['msg'] = '添加成功';
			}
			else
			{
				$res['sign'] = '0';
				$res['msg'] = '添加失败';
			}
		}
		
		echoJSON($res);
	}
	
	
	if($parm['m'] == 'roleStatus')
	{
		if($parm['status'] == '3')
		{
			if(!adminpermission('X','100000','100004'))
			{
				$res['sign'] = '-2';
				echoJSON($res);
				exit;
			}
		}
		else
		{
			if(!adminpermission('X','100000','100003'))
			{
				$res['sign'] = '-2';
				echoJSON($res);
				exit;
			}
		}
		
		if(!empty($parm['id']))
		{
			unset($where,$data);
			$where['id'] = $parm['id'];
			$info = $sqlTools->getInfo('role',$where);
			if($info)
			{
				unset($where,$data);
				$where['id'] = $info['id'];
				$data['status'] = $parm['status'];
				$upres = $sqlTools->setInfo('role',$where,$data);
				if($upres)
				{
					saveOpLogInfo('role',$info['id'],'更新角色状态('.$parm['str'].')');
					
					$res['sign'] = '1';
					$res['msg'] = '操作成功';
				}
				else
				{
					$res['sign'] = '0';
					$res['msg'] = '操作失败';
				}
			}
			else
			{
				$res['sign'] = '0';
				$res['msg'] = '数据错误';
			}
		}
		else
		{
			$res['sign'] = '0';
			$res['msg'] = '数据错误';
		}
		
		echoJSON($res);
	}
	
	if($parm['m'] == 'saveRole')
	{
		if(!empty($parm['id']))
		{
			if(!adminpermission('X','100000','100002'))
			{
				$res['sign'] = '-2';
				echoJSON($res);
				exit;
			}
			//更新
			unset($where,$data);
			$where['id'] = $parm['id'];
			$data['name'] = $parm['name'];
			$data['permission'] = json_encode($parm['permission']);
			$data['status'] = $parm['status'];
			$upres = $sqlTools->setInfo('role',$where,$data);
			if($upres)
			{
				saveOpLogInfo('role',$parm['id'],'更新角色信息');
				$res['sign'] = '1';
				$res['msg'] = '更新成功';
			}
			else
			{
				$res['sign'] = '0';
				$res['msg'] = '更新失败';
			}
		}
		else
		{
			if(!adminpermission('X','100000','100001'))
			{
				$res['sign'] = '-2';
				echoJSON($res);
				exit;
			}
			//添加
			unset($data);
			$data['name'] = $parm['name'];
			$data['permission'] = json_encode($parm['permission']);
			$data['status'] = $parm['status'];
			$data['addtime'] = time();
			$data['adduser'] = getLoginAdminInfo('id');
			$addres = $sqlTools->addInfo('role',$data);
			if($addres)
			{
				saveOpLogInfo('role',$addres,'添加角色信息');
				$res['sign'] = '1';
				$res['msg'] = '添加成功';
			}
			else
			{
				$res['sign'] = '0';
				$res['msg'] = '添加失败';
			}
		}
		
		echoJSON($res);
	}
	
	if($parm['m'] == 'gggStatus')
	{
		if($parm['status'] == '0')
		{
			if(!adminpermission('N','100000','110004'))
			{
				$res['sign'] = '-2';
				echoJSON($res);
				exit;
			}
		}
		else
		{
			if(!adminpermission('N','100000','110003'))
			{
				$res['sign'] = '-2';
				echoJSON($res);
				exit;
			}
		}
		
		if(!empty($parm['id']))
		{
			unset($where,$data);
			$where['id'] = $parm['id'];
			$info = $sqlTools->getInfo('banner',$where);
			if($info)
			{
				unset($where,$data);
				$where['id'] = $info['id'];
				$data['status'] = $parm['status'];
				$upres = $sqlTools->setInfo('banner',$where,$data);
				if($upres)
				{
					saveOpLogInfo('gonggao',$info['id'],'更新Banner状态('.$parm['str'].')');
					
					$res['sign'] = '1';
					$res['msg'] = '操作成功';
				}
				else
				{
					$res['sign'] = '0';
					$res['msg'] = '操作失败';
				}
			}
			else
			{
				$res['sign'] = '0';
				$res['msg'] = '数据错误';
			}
		}
		else
		{
			$res['sign'] = '0';
			$res['msg'] = '数据错误';
		}
		
		echoJSON($res);
	}
	
	
	if($parm['m'] == 'saveGuanggao')
	{
		if(!empty($parm['id']))
		{
			if(!adminpermission('N','100000','100002'))
			{
				$res['sign'] = '-2';
				echoJSON($res);
				exit;
			}
			//更新
			unset($where,$data);
			$where['id'] = $parm['id'];
			$data['sort'] = intval($parm['sort']);
			$data['title'] = $parm['title'];
			$data['tupian'] = $parm['tupian'];
			$data['url'] = $parm['url'];
			$data['start'] = strtotime($parm['start']);
			$data['end'] = strtotime($parm['end']);
			$data['status'] = $parm['status'];
			$upres = $sqlTools->setInfo('banner',$where,$data);
			if($upres)
			{
				saveOpLogInfo('banner',$parm['id'],'更新Banner信息');
				$res['sign'] = '1';
				$res['msg'] = '更新成功';
			}
			else
			{
				$res['sign'] = '0';
				$res['msg'] = '更新失败';
			}
		}
		else
		{
			if(!adminpermission('N','100000','100001'))
			{
				$res['sign'] = '-2';
				echoJSON($res);
				exit;
			}
			//添加
			unset($data);
			$data['sort'] = intval($parm['sort']);
			$data['title'] = $parm['title'];
			$data['type'] = $parm['type'];
			$data['tupian'] = $parm['tupian'];
			$data['url'] = $parm['url'];
			$data['start'] = strtotime($parm['start']);
			$data['end'] = strtotime($parm['end']);
			$data['status'] = $parm['status'];
			$data['addtime'] = time();
			$addres = $sqlTools->addInfo('banner',$data);
			if($addres)
			{
				saveOpLogInfo('banner',$addres,'添加Banner信息');
				$res['sign'] = '1';
				$res['msg'] = '添加成功';
			}
			else
			{
				$res['sign'] = '0';
				$res['msg'] = '添加失败';
			}
		}
		
		echoJSON($res);
	}
	
	
	if($parm['m'] == 'ggStatus')
	{
		if($parm['status'] == '0')
		{
			if(!adminpermission('N','110000','110004'))
			{
				$res['sign'] = '-2';
				echoJSON($res);
				exit;
			}
		}
		else
		{
			if(!adminpermission('N','110000','110003'))
			{
				$res['sign'] = '-2';
				echoJSON($res);
				exit;
			}
		}
		
		if(!empty($parm['id']))
		{
			unset($where,$data);
			$where['id'] = $parm['id'];
			$info = $sqlTools->getInfo('gonggao',$where);
			if($info)
			{
				unset($where,$data);
				$where['id'] = $info['id'];
				$data['status'] = $parm['status'];
				$upres = $sqlTools->setInfo('gonggao',$where,$data);
				if($upres)
				{
					saveOpLogInfo('gonggao',$info['id'],'更新公告状态('.$parm['str'].')');
					
					$res['sign'] = '1';
					$res['msg'] = '操作成功';
				}
				else
				{
					$res['sign'] = '0';
					$res['msg'] = '操作失败';
				}
			}
			else
			{
				$res['sign'] = '0';
				$res['msg'] = '数据错误';
			}
		}
		else
		{
			$res['sign'] = '0';
			$res['msg'] = '数据错误';
		}
		
		echoJSON($res);
	}
	
	if($parm['m'] == 'saveGonggao')
	{
		if(!empty($parm['id']))
		{
			if(!adminpermission('N','110000','110002'))
			{
				$res['sign'] = '-2';
				echoJSON($res);
				exit;
			}
			//更新
			unset($where,$data);
			$where['id'] = $parm['id'];
			$data['title'] = $parm['title'];
			$data['fbtime'] = strtotime($parm['start']);
			$data['content'] = $parm['content'];
			$data['status'] = $parm['status'];
			$upres = $sqlTools->setInfo('gonggao',$where,$data);
			if($upres)
			{
				saveOpLogInfo('gonggao',$parm['id'],'更新公告信息');
				$res['sign'] = '1';
				$res['msg'] = '更新成功';
			}
			else
			{
				$res['sign'] = '0';
				$res['msg'] = '更新失败';
			}
		}
		else
		{
			if(!adminpermission('N','110000','110001'))
			{
				$res['sign'] = '-2';
				echoJSON($res);
				exit;
			}
			//添加
			unset($data);
			$data['title'] = $parm['title'];
			$data['fbtime'] = strtotime($parm['start']);
			$data['content'] = $parm['content'];
			$data['status'] = $parm['status'];
			$data['addtime'] = time();
			$addres = $sqlTools->addInfo('gonggao',$data);
			if($addres)
			{
				saveOpLogInfo('gonggao',$addres,'添加公告信息');
				$res['sign'] = '1';
				$res['msg'] = '添加成功';
			}
			else
			{
				$res['sign'] = '0';
				$res['msg'] = '添加失败';
			}
		}
		
		echoJSON($res);
	}
	
	if($parm['m'] == 'saveChanPin')
	{
		unset($where);
		$where['id'] = $parm['pt_id'];
		$pingtai = $sqlTools->getInfo('pingtai', $where);
		
		if(empty($pingtai))
		{
			$res['sign'] = '0';
			echoJSON($res);
			exit;
		}
			
			
		if(!empty($parm['cp_id']))
		{
			if(!adminpermission('P','110000','110002'))
			{
				$res['sign'] = '-2';
				echoJSON($res);
				exit;
			}
			
			//更新
			unset($where,$data);
			$where['id'] = $parm['cp_id'];
			
			$data['lc_type'] = $pingtai['lc_type'];
			
			$data['pt_id'] = $parm['pt_id'];
			$data['cp_type'] = $parm['cp_type'];
			$data['cp_mc'] = $parm['cp_mc'];
			$data['cp_yqnh'] = round(floatval($parm['cp_yqnh']),2);
			$data['cp_qtje'] = round(floatval($parm['cp_qtje']),2);
			$data['cp_tzqx'] = $parm['cp_tzqx'];
			$data['cp_hkfs'] = $parm['cp_hkfs'];
			$data['cp_zsy'] = $parm['cp_zsy'];
			$data['cp_lxxs'] = $parm['cp_lxxs'];
			$data['cp_lx'] = round(floatval($parm['cp_lx']),2);
			$data['cp_fl'] = round(floatval($parm['cp_fl']),2);
			$data['cp_hb'] = round(floatval($parm['cp_hb']),2);
			$data['cp_flsj'] = $parm['cp_flsj'];
			$data['cp_zqzr'] = $parm['cp_zqzr'];
			$data['cp_qxr'] = $parm['cp_qxr'];
			$data['cp_lxglf'] = $parm['cp_lxglf'];
			$data['cp_fllx'] = $parm['cp_fllx'];
			$data['cp_flgl'] = $parm['cp_flgl'];
			$data['cp_tzlj'] = $parm['cp_tzlj'];
			$data['cp_status'] = $parm['status'];
			$data['cp_style'] = $parm['cp_style'];
			$data['cp_tzqxlx'] = $parm['cp_tzqxlx'];
			$data['cp_xiane'] = $parm['cp_xiane'];
			$data['is_new'] = $parm['is_new'];
			$upres = $sqlTools->setInfo('chanpin',$where,$data);
			if($upres)
			{
				unset($query);
				$query['cp_id'] = $parm['cp_id'];
				$resdel = _SqlTool::removeInfo('cp_gdfa', $query);
				foreach ($parm['cp_gdfa'] as $k => $v)
				{
					unset($temp);
					$temp['pt_id'] = $parm['pt_id'];
					$temp['cp_id'] = $parm['cp_id'];
					$temp['tzje'] = floatval($v['tzje']);
					$temp['lixi'] = floatval($v['lx']);
					$temp['fanli'] = floatval($v['fl']);
					$temp['hongbao'] = floatval($v['hb']);
					_SqlTool::addInfo('cp_gdfa', $temp);
				}
				
				saveOpLogInfo('chanpin',$parm['cp_id'],'更新产品信息');
				$res['sign'] = '1';
				$res['msg'] = '更新成功';
			}
			else
			{
				$res['sign'] = '0';
				$res['msg'] = '更新失败';
			}
		}    
		else
		{
			if(!(adminpermission('P','110000','110001') || adminpermission('P','100000','100005')))
			{
				$res['sign'] = '-2';
				echoJSON($res);
				exit;
			}
			//添加
			$data['lc_type'] = $pingtai['lc_type'];
			$data['pt_id'] = $parm['pt_id'];
			$data['cp_type'] = $parm['cp_type'];
			$data['cp_mc'] = $parm['cp_mc'];
			$data['cp_yqnh'] = round(floatval($parm['cp_yqnh']),2);
			$data['cp_qtje'] = round(floatval($parm['cp_qtje']),2);
			$data['cp_tzqx'] = $parm['cp_tzqx'];
			$data['cp_hkfs'] = $parm['cp_hkfs'];
			$data['cp_zsy'] = $parm['cp_zsy'];
			$data['cp_lxxs'] = $parm['cp_lxxs'];
			$data['cp_lx'] = round(floatval($parm['cp_lx']),2);
			$data['cp_fl'] = round(floatval($parm['cp_fl']),2);
			$data['cp_hb'] = round(floatval($parm['cp_hb']),2);
			$data['cp_flsj'] = $parm['cp_flsj'];
			$data['cp_zqzr'] = $parm['cp_zqzr'];
			$data['cp_qxr'] = $parm['cp_qxr'];
			$data['cp_lxglf'] = $parm['cp_lxglf'];
			$data['cp_fllx'] = $parm['cp_fllx'];
			$data['cp_flgl'] = $parm['cp_flgl'];
			$data['cp_tzlj'] = $parm['cp_tzlj'];
			$data['cp_status'] = $parm['status'];
			$data['addtime'] = time();
			$data['cp_style'] = $parm['cp_style'];
			$data['cp_tzqxlx'] = $parm['cp_tzqxlx'];
			$data['cp_xiane'] = $parm['cp_xiane'];
			$data['is_new'] = $parm['is_new'];
			unset($cp_gdfa);
			
			$addres = $sqlTools->addInfo('chanpin',$data);

			if($addres)
			{
				foreach ($parm['cp_gdfa'] as $k => $v)
				{
					unset($temp);
					$temp['pt_id'] = $parm['pt_id'];
					$temp['cp_id'] = $addres;
					$temp['tzje'] = floatval($v['tzje']);
					$temp['lixi'] = floatval($v['lx']);
					$temp['fanli'] = floatval($v['fl']);
					$temp['hongbao'] = floatval($v['hb']);
					_SqlTool::addInfo('cp_gdfa', $temp);
				}
				
				saveOpLogInfo('chanpin',$addres,'添加产品信息');
				$res['sign'] = '1';
				$res['msg'] = '添加成功';
			}
			else
			{
				$res['sign'] = '0';
				$res['msg'] = '添加失败';
			}
		}
		
		echoJSON($res);
	}
	
	
	if($parm['m'] == 'ptStatus')
	{
		if($parm['status'] == '0')
		{
			if(!adminpermission('P','100000','100004'))
			{
				$res['sign'] = '-2';
				echoJSON($res);
				exit;
			}
		}
		else
		{
			if(!adminpermission('P','100000','100003'))
			{
				$res['sign'] = '-2';
				echoJSON($res);
				exit;
			}
		}
		
		
		if(!empty($parm['id']))
		{
			unset($where,$data);
			$where['id'] = $parm['id'];
			$info = $sqlTools->getInfo('pingtai',$where);
			if($info)
			{
				unset($where,$data);
				$where['id'] = $info['id'];
				$data['status'] = $parm['status'];
				$upres = $sqlTools->setInfo('pingtai',$where,$data);
				if($upres)
				{
					saveOpLogInfo('pingtai',$info['id'],'更新平台状态('.$parm['str'].')');
					
					$res['sign'] = '1';
					$res['msg'] = '操作成功';
				}
				else
				{
					$res['sign'] = '0';
					$res['msg'] = '操作失败';
				}
			}
			else
			{
				$res['sign'] = '0';
				$res['msg'] = '数据错误';
			}
		}
		else
		{
			$res['sign'] = '0';
			$res['msg'] = '数据错误';
		}
		
		echoJSON($res);
	}
	
	if($parm['m'] == 'savePingtai')
	{
		if(!adminpermission('P','100000'))
		{
			$res['sign'] = '-2';
			echoJSON($res);
			exit;
		}
		
		if(!empty($parm['id']))
		{
			//更新
			unset($where,$data);
			$where['id'] = $parm['id'];
			$data['pt_type'] = $parm['pt_type'];
			$data['lc_type'] = $parm['lc_type'];
			$data['pt_name'] = $parm['pt_name'];
			$data['pt_logo'] = $parm['pt_logo'];
			$data['pt_desc'] = $parm['pt_desc'];
			$data['pt_bj'] = $parm['pt_bj'];
			$data['pt_yqnh'] = $parm['pt_yqnh'];
			$data['pt_zgfl'] = $parm['pt_zgfl'];
			$data['pt_fxdj'] = $parm['pt_fxdj'];
			$data['pt_sxsj'] = $parm['pt_sxsj'];
			$data['pt_szd'] = $parm['pt_szd'];
			$data['pt_zyyw'] = $parm['pt_zyyw'];
			$data['pt_yhcg'] = $parm['pt_yhcg'];
			$data['pt_yhlj'] = $parm['pt_yhlj'];
			$data['pt_cjed'] = $parm['pt_cjed'];
			$data['pt_txfy'] = $parm['pt_txfy'];
			$data['pt_lxglf'] = $parm['pt_lxglf'];
			$data['pt_zqzr'] = $parm['pt_zqzr'];
			$data['pt_zcfs'] = $parm['pt_zcfs'];
			$data['status'] = $parm['status'];
			
			$upres = $sqlTools->setInfo('pingtai',$where,$data);
			if($upres)
			{
				saveOpLogInfo('pingtai',$parm['id'],'更新平台信息');
				$res['sign'] = '1';
				$res['msg'] = '更新成功';
			}
			else
			{
				$res['sign'] = '0';
				$res['msg'] = '更新失败';
			}
		}    
		else
		{
			//添加
			$data['pt_type'] = $parm['pt_type'];
			$data['lc_type'] = $parm['lc_type'];
			$data['pt_name'] = $parm['pt_name'];
			$data['pt_logo'] = $parm['pt_logo'];
			$data['pt_desc'] = $parm['pt_desc'];
			$data['pt_bj'] = $parm['pt_bj'];
			$data['pt_yqnh'] = $parm['pt_yqnh'];
			$data['pt_zgfl'] = $parm['pt_zgfl'];
			$data['pt_fxdj'] = $parm['pt_fxdj'];
			$data['pt_sxsj'] = $parm['pt_sxsj'];
			$data['pt_szd'] = $parm['pt_szd'];
			$data['pt_zyyw'] = $parm['pt_zyyw'];
			$data['pt_yhcg'] = $parm['pt_yhcg'];
			$data['pt_yhlj'] = $parm['pt_yhlj'];
			$data['pt_cjed'] = $parm['pt_cjed'];
			$data['pt_txfy'] = $parm['pt_txfy'];
			$data['pt_lxglf'] = $parm['pt_lxglf'];
			$data['pt_zqzr'] = $parm['pt_zqzr'];
			$data['pt_zcfs'] = $parm['pt_zcfs'];
			$data['status'] = $parm['status'];
			$data['addtime'] = time();
			
			$addres = $sqlTools->addInfo('pingtai',$data);
			
			if($addres)
			{
				saveOpLogInfo('pingtai',$addres,'添加平台信息');
				$res['sign'] = '1';
				$res['msg'] = '添加成功';
			}
			else
			{
				$res['sign'] = '0';
				$res['msg'] = '添加失败';
			}
		}
		
		echoJSON($res);
	}
	
	
	if($parm['m'] == 'login')
	{
		$username = getParam('username','post');
		$password = getParam('password','post');
		$seccode = getParam('seccode','post');
		$res['sign'] = '0';
		$seccode = '111';
		if(empty($seccode))
		{
			$res['msg'] = '验证码错误!';
		}
		else
		{
			//$_SESSION['verfyCode'] = '';
			$loginparm['loginname'] = $username;
			
			$admin = _Admin::getAdminInfo($loginparm);
			
			
			
			
			if(!empty($admin))
			{
				if(md5($password) == $admin['password'])
				{
					$res['sign'] = '1';
					$res['msg'] = '登录成功';
					
					//更新信息
					unset($data,$where);
					$where['id'] = $admin['id'];
					$data['lastnums'] = $admin['lastnums'] + 1;
					$data['lastip'] = getClientIP();
					$data['lasttime'] = time();
					
					$data['loginkey'] = md5($data['lasttime'].$admin['id'].$data['lastnums'].$data['lastip'].'!@#$%^&*()!@#$EW');
					
					_Admin::setAdminInfo($where, $data);
					
					setcookie("adminloginkey",$data['loginkey'], time()+3600*24,'/');
					/*unset($where);
					$where['id'] = $admin['roleid'];
					
					$role = _SqlTool::getInfo('role', $where);
					
					if(!empty($role))
					{
						$admin['permission'] = json_decode($role['permission'],true);
					}
					
					$_SESSION['loginadmin'] = $admin;*/
				}
				else
				{
					$res['msg'] = '登录失败,密码错误!';
				}
			}
			else
			{
				$res['msg'] = '登录失败,请检查您的输入!';
			}
		}
		
		echoJSON($res);
	}


	function pageshow_rili($page,$total)
	{
		$tab=7;
		if($total<1)
		{
			$total = 1;
		}	
		
		if($page<1)
		{
			$total = 1;
		}
		
			
		if($total <= $tab){
			$_start = 1;
			$_end = $total;
		}elseif($page <= ceil($tab/2)){
			$_start = 1;
			$_end = $tab;
		}elseif($page >= $total - $tab/2){
			$_start = $total - ($tab -1);
			$_end = $total ;
		}else{
			$_start = $page - ceil($tab/2) +1 ;
			$_end = $page + ceil($tab/2) -1;
		}
		$_page = $page;
		$_prepage = ($page<=1)?1:($page-1);
		$_nextpage = ($page>=$total)?$total:($page+1);
		
		$return['_page'] = intval($_page);
		$return['_prepage'] = intval($_prepage);
		$return['_nextpage'] = intval($_nextpage);
		$return['_totlepage'] = intval($total);
		for($i=$_start;$i<=$_end;$i++)
		{
			$return['pagelist'][] = array('p'=>$i);
		}
		
		return $return;
	}
